package com.ruoyi.maode.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Value;

import java.util.Date;
import java.util.List;

@Mapper
public interface FlowableMapper {

    /**
     * 更新已结束任务状态
     * @param processInstanceId
     * @param status
     */
    void updateBusinessStatus(@Param("processInstanceId") String processInstanceId,@Param("status") String status);

    @Update("UPDATE act_hi_procinst SET BUSINESS_STATUS_ = '审批完成',END_TIME_ = #{date} ,END_ACT_ID_ = #{endId}WHERE PROC_INST_ID_ = #{processInstanceId}")
    void updateStatus(@Param("processInstanceId") String processInstanceId, @Param("date")Date date,@Param("endId")String endId);


    /**
     * 删除重复的历史taskId
     * @param taskId
     */
    void deleteTaskId(@Param("taskId") String taskId);

    void deleteHisToryTaskId(@Param("taskId") String taskId);

    @InterceptorIgnore(blockAttack = "true")
    @Delete("DELETE act_hi_actinst\n" +
            "        FROM act_hi_actinst\n" +
            "                 JOIN (\n" +
            "            SELECT ID_\n" +
            "            FROM act_hi_actinst\n" +
            "            WHERE END_TIME_ IS NULL\n" +
            "              AND ACT_NAME_ = '品质部长判定'\n" +
            "              AND ACT_TYPE_ = 'userTask'\n" +
            "            ORDER BY START_TIME_ DESC\n" +
            "            LIMIT 1\n" +
            "        ) AS subquery\n" +
            "                      ON act_hi_actinst.ID_ = subquery.ID_;")
    void deleteHistoryDetail();

    @Select("SELECT ID_ FROM act_ru_task WHERE PROC_INST_ID_ = #{processInstanceId}")
    @Results({
            @Result(property = "id", column = "ID_")
    })
    List<String> selectTaskId(@Param("processInstanceId") String processInstanceId);
}
